# 使用open打开文件
#
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "r")
# print(f)
# print(type(f))
#
# # 关闭文件
# f.close()
# count = 0
# a = []
# while True:
#     f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "r")
#     # a.append(f) 8189
#     count += 1
# #     print(count)
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "w")
# f.write("hello")
# f.close()
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "w")
# f.close()
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "a")
# f.write("hello\n")
# f.close()
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "a")
# f.write("world")
# f.close()
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "a")
# f.write("hello\n")
# f.close()
# f.write("world")
# 读文件
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "r", encoding="utf8")
# result = f.read(5)
# print(result)
# f.close()
# 按行读取
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "r", encoding="utf8")
# for line in f:
#     print(f"line = {line}", end="")
# f.close()
# readlines
# f = open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "r", encoding="utf8")
# lines = f.readlines()
# print(lines)
# f.close()

# 上下文管理器
# 防止遗漏文件关闭操作
def func():
    with open("E:\\bit\\pythoncode\\pythonProject2\\text.txt", "r", encoding="utf8") as f:
        if cond:
            return
        ###### 代码
        ###### 代码
        ###### 代码
        ###### 代码
        ###### 代码
        if cond:
            return
        ###### 代码
        ###### 代码
        ###### 代码
        ###### 代码
        ###### 代码
        if cond:
            return
        ###### 代码
        ###### 代码
        ###### 代码
        ###### 代码
        ###### 代码


